package 二叉树相关问题;

public class 路径总和 {

    public boolean hasPathSum(TreeNode root, int targetSum) {
         if (root==null)
             return false;
         int sum=0;
         sum+=root.val;
         if (sum==targetSum && root.left==null && root.right==null)
             return true;
         return hasPathSum(root.left,targetSum-root.val) || hasPathSum(root.right,targetSum-root.val);
    }
}
